package com.shanghaionstar.report.bean;

import android.support.annotation.StringDef;

import com.onstar.cn.mag.enumtype.RemoteCommandsType;
import com.onstar.cn.map.common.PoiItemInfo;
import com.shanghaionstar.enumtype.FunctionNameFindId;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * report传参bean
 * Created by 6335yz on 2016/11/10.
 */
public class ReportReqParam {
    @StringDef({"0", "1", "2", "3"})
    @Retention(RetentionPolicy.SOURCE)
    public @interface TYPE {
    }

    public String type;//0 Click,1 Error, 2 Crash,3 interaction

    @StringDef({"0", "1", "2", "3", "4", "9"})
    @Retention(RetentionPolicy.SOURCE)
    public @interface CHANNELID {
    }

    public String channelId;//0 mobile,1 web, 2 MWeb, 3 WeChat, 4 Portal, 9 other

    @StringDef({"0", "1", "2", "3", "9"})
    @Retention(RetentionPolicy.SOURCE)
    public @interface DEVICETYPE {
    }

    public String deviceType;//0 ANDROID,1 IOS, 2 WeChat, 3 Web, 9 Other

    @StringDef({"0", "1", ""})
    @Retention(RetentionPolicy.SOURCE)
    public @interface OPERATIONTYPE {
    }

    public String operationType;//0 open,1 close, 2 succeed, 3 fail

    @StringDef({"0", "1", "2"})
    @Retention(RetentionPolicy.SOURCE)
    public @interface RESULT {
    }

    public String result;//0 成功,1 失败, 2 异常

    @StringDef({"0", "1", "2", "3", "9"})//0 Banner,1 BroadCast,2 Notification,3 URL,9 other content
    @Retention(RetentionPolicy.SOURCE)
    public @interface OBJECTTYPE {
    }

    public String objectType;//0 banner,1 Broadcast, 2 Notification , 9 其他content类型

    public String functionNameFindId;
    public String objectID;//如bannerid

    //extra 信息
    public String error;//报错信息
    public double latitude;//
    public double longitude;//

    public long startTimestamp;
    public long endTimestamp;





    public PoiItemInfo poiItemInfo;//客户端下发TBT，ODD的经纬度需要采集,传到后台。放在扩展字段中

    public ReportReqParam(@TYPE String type, @CHANNELID String channelId, @DEVICETYPE String deviceType,
                          @OPERATIONTYPE String operationType, @RESULT String result, @OBJECTTYPE String objectType,
                          String functionNameFindId, String objectID, PoiItemInfo poiItemInfo, String error, double latitude, double longitude,long startTimestamp,long endTimestamp) {
        this.type = type;
        this.channelId = channelId;
        this.deviceType = deviceType;
        this.operationType = operationType;
        this.result = result;
        this.objectType = objectType;
        this.functionNameFindId = functionNameFindId;
        this.objectID = objectID;
        this.poiItemInfo = poiItemInfo;
        this.error = error;
        this.latitude = latitude;
        this.longitude = longitude;
        this.startTimestamp = startTimestamp;
        this.endTimestamp = endTimestamp;

    }

    public static class ReportReqParamBuilder {
        private String type;//0 Click,1 Error, 2 Crash
        private String channelId;//0 mobile,1 web, 2 MWeb, 3 WeChat, 4 Portal, 9 other
        private String deviceType;//0 ANDROID,1 IOS, 2 WeChat, 3 Web, 9 Other
        private String operationType;//0 open,1 close
        private String result;//0 成功,1 失败, 2 异常
        private String objectType;//0 banner,1 Broadcast, 2 Notification , 9 其他content类型
        private String functionNameFindId;
        private String objectID;//如bannerid
        private PoiItemInfo poiItemInfo;//客户端下发TBT，ODD的经纬度需要采集,传到后台。放在扩展字段中
        private String error;//报错信息
        private double latitude;//
        private double longitude;//

        private long startTimestamp;
        private long endTimestamp;

        public ReportReqParamBuilder latitude(double latitude) {
            this.latitude = latitude;
            return this;
        }

        public ReportReqParamBuilder longitude(double longitude) {
            this.longitude = longitude;
            return this;
        }

        public ReportReqParamBuilder error(String error) {
            this.error = error;
            return this;
        }

        public ReportReqParamBuilder poiItemInfo(PoiItemInfo poiItemInfo) {
            this.poiItemInfo = poiItemInfo;
            return this;
        }

        public ReportReqParamBuilder type(@TYPE String type) {
            this.type = type;
            return this;
        }

        public ReportReqParamBuilder channelId(@CHANNELID String channelId) {
            this.channelId = channelId;
            return this;
        }

        public ReportReqParamBuilder deviceType(@DEVICETYPE String deviceType) {
            this.deviceType = deviceType;
            return this;
        }

        public ReportReqParamBuilder operationType(@OPERATIONTYPE String operationType) {
            this.operationType = operationType;
            return this;
        }

        public ReportReqParamBuilder result(@RESULT String result) {
            this.result = result;
            return this;
        }

        public ReportReqParamBuilder objectType(@OBJECTTYPE String objectType) {
            this.objectType = objectType;
            return this;
        }

        public ReportReqParamBuilder functionNameFindId(String functionNameFindId) {
            this.functionNameFindId = functionNameFindId;
            return this;
        }

        public ReportReqParamBuilder objectID(String objectID) {
            this.objectID = objectID;
            return this;
        }
        public ReportReqParamBuilder startTimestamp(long startTimestamp) {
            this.startTimestamp = startTimestamp;
            return this;
        }
        public ReportReqParamBuilder endTimestamp(long endTimestamp) {
            this.endTimestamp = endTimestamp;
            return this;
        }

        public ReportReqParam createReportReqParam() {
            return new ReportReqParam
                    (type, channelId, deviceType,
                            operationType, result, objectType,
                            functionNameFindId, objectID, poiItemInfo, error, latitude, longitude,startTimestamp,endTimestamp);
        }
    }


    //////////////////得到各种请求参数开始/////////////////////////////

    //////////////////导航发送结果/////////////////////////////
    public static ReportReqParam getTBTOddReportParams(RemoteCommandsType remoteCommandsType, boolean isSuccess, String error) {
        String functionId = "";
        if (remoteCommandsType == RemoteCommandsType.COMMANDS_TBT_ROUTE) {
            functionId = FunctionNameFindId.SendingTBT.getStringValue();
        } else if (remoteCommandsType == RemoteCommandsType.COMMANDS_NAV_DESTINATION) {
            functionId = FunctionNameFindId.SendingODD.getStringValue();
        }
        return new ReportReqParam.ReportReqParamBuilder().channelId("0")
                .deviceType("0")
                .functionNameFindId(functionId)
                .objectID("")
                .objectType("9")
                .operationType("")
                .result(isSuccess ? "0" : "1")
                .error(error)
                .type("3").createReportReqParam();
    }

    public static ReportReqParam getTBTOddReportParams(RemoteCommandsType remoteCommandsType, boolean isSuccess) {
        return getTBTOddReportParams(remoteCommandsType, isSuccess, "");
    }

    //////////////////导航发送点击/////////////////////////////
    public static ReportReqParam getTBTOddClickParams(String functionNameFindId, double latitude, double longitude) {
        return new ReportReqParamBuilder().channelId("0")
                .deviceType("0")
                .latitude(latitude)
                .longitude(longitude)
                .functionNameFindId(functionNameFindId)
                .objectID("")
                .objectType("9")
                .operationType("")
                .result("0")
                .type("0").createReportReqParam();
    }

    //////////////////导航页面车辆位置结果/////////////////////////////
    public static ReportReqParam getVehicleLocateReqParam(FunctionNameFindId functionNameFindId, boolean isSuccess, String error) {
        return new ReportReqParam.ReportReqParamBuilder()
                .channelId("0")
                .deviceType("0")
                .functionNameFindId(functionNameFindId.getStringValue())
                .objectID("")
                .objectType("9")
                .operationType("")
                .result(isSuccess ? "0" : "1")
                .type("3")
                .error(error)
                .createReportReqParam();
    }

    //////////////////车辆操作结果/////////////////////////////
    public static ReportReqParam getRemoteCommandReportParams(String functionNameFindId, boolean isSuccess, String error) {
        return new ReportReqParam.ReportReqParamBuilder().channelId("0")
                .deviceType("0")
                .functionNameFindId(functionNameFindId)
                .objectID("")
                .objectType("9")
                .operationType("")
                .result(isSuccess ? "0" : "1")
                .error(error)
                .type("3").createReportReqParam();
    }

    public static ReportReqParam getRemoteCommandReportParams(String functionNameFindId, boolean isSuccess) {
        return getRemoteCommandReportParams(functionNameFindId, isSuccess, "");
    }

    //////////////////登录结果/////////////////////////////
    public static ReportReqParam getLoginReqParm(boolean isSuccess, String error) {
        return new ReportReqParam.ReportReqParamBuilder().channelId("0")
                .deviceType("0")
                .functionNameFindId(FunctionNameFindId.loginregister_Login.getStringValue())
                .objectID("")
                .objectType("9")
                .operationType("")
                .result(isSuccess ? "0" : "1")
                .type("3")
                .error(error)
                .createReportReqParam();
    }

    public static ReportReqParam getLoginReqParm(boolean isSuccess) {
        return getLoginReqParm(isSuccess, "");
    }

    //////////////////WIFI获取结果/////////////////////////////
    public static ReportReqParam getWIFIInfoReqParm(boolean isSuccess, String error) {
        return new ReportReqParam.ReportReqParamBuilder().channelId("0")
                .deviceType("0")
                .functionNameFindId(FunctionNameFindId.Find_VehicularWiFi.getStringValue())
                .objectID("")
                .objectType("9")
                .operationType("")
                .result(isSuccess ? "0" : "1")
                .type("3")
                .error(error)
                .createReportReqParam();
    }

    //////////////////WIFI获取结果/////////////////////////////
    public static ReportReqParam getWIFIInfoReqParm(boolean isSuccess) {
        return getWIFIInfoReqParm(isSuccess, "");
    }

    //////////////////WIFI设置结果/////////////////////////////
    public static ReportReqParam getWIFISetReqParm(boolean isSuccess, String error) {
        return new ReportReqParam.ReportReqParamBuilder().channelId("0")
                .deviceType("0")
                .functionNameFindId(FunctionNameFindId.WIFIsavepassword.getStringValue())
                .objectID("")
                .objectType("9")
                .operationType("")
                .result(isSuccess ? "0" : "1")
                .type("3")
                .error(error)
                .createReportReqParam();
    }

    public static ReportReqParam getWIFISetReqParm(boolean isSuccess) {
        return getWIFISetReqParm(isSuccess, "");
    }

    //////////////////BANNER点击结果/////////////////////////////
    public static ReportReqParam getBannerClickReqParm(String bannerId) {
        return new ReportReqParam.ReportReqParamBuilder().channelId("0")
                .deviceType("0")
                .functionNameFindId(FunctionNameFindId.Home_Banner.getStringValue())
                .objectID(bannerId)
                .objectType("0")
                .operationType("")
                .result("0")
                .type("0")
                .createReportReqParam();
    }

    //////////////////充电模式返回结果/////////////////////////////
    public static ReportReqParam getChargeModeInfoReqParm(boolean isSuccess, String error) {
        return new ReportReqParam.ReportReqParamBuilder().channelId("0")
                .deviceType("0")
                .functionNameFindId(FunctionNameFindId.Charge_Get.getStringValue())
                .objectID("")
                .objectType("9")
                .operationType("")
                .result(isSuccess ? "0" : "1")
                .type("3")
                .error(error)
                .createReportReqParam();
    }
    ////////////供调用的方法/////////////
    public static ReportReqParam getChargeModeInfoReqParm(boolean isSuccess) {
        return getChargeModeInfoReqParm(isSuccess, "");
    }

    //////////////////充电模式设置返回结果/////////////////////////////
    public static ReportReqParam getSetChargeModeReqParm(boolean isSuccess, String error) {
        return new ReportReqParam.ReportReqParamBuilder().channelId("0")
                .deviceType("0")
                .functionNameFindId(FunctionNameFindId.Charge_Save.getStringValue())
                .objectID("")
                .objectType("9")
                .operationType("")
                .result(isSuccess ? "0" : "1")
                .type("3")
                .error(error)
                .createReportReqParam();
    }

    ////////////供调用的方法/////////////
    public static ReportReqParam getSetChargeModeReqParm(boolean isSuccess) {
        return getSetChargeModeReqParm(isSuccess, "");
    }

    //////////////////充电时间返回结果/////////////////////////////
    public static ReportReqParam getSetChargeTimeReqParm(boolean isSuccess, String error) {
        return new ReportReqParam.ReportReqParamBuilder().channelId("0")
                .deviceType("0")
                .functionNameFindId(FunctionNameFindId.PhevSaveTime.getStringValue())
                .objectID("")
                .objectType("9")
                .operationType("")
                .result(isSuccess ? "0" : "1")
                .type("3")
                .error(error)
                .createReportReqParam();
    }

    ////////////供调用的方法/////////////
    public static ReportReqParam getSetChargeTimeReqParm(boolean isSuccess) {
        return getSetChargeTimeReqParm(isSuccess, "");
    }
    //////////////////充电时间返回结果/////////////////////////////
    public static ReportReqParam getChargeTimeReqParm(boolean isSuccess, String error) {
        return new ReportReqParam.ReportReqParamBuilder().channelId("0")
                .deviceType("0")
                .functionNameFindId(FunctionNameFindId.PhevTime_Get.getStringValue())
                .objectID("")
                .objectType("9")
                .operationType("")
                .result(isSuccess ? "0" : "1")
                .type("3")
                .error(error)
                .createReportReqParam();
    }

    ////////////供调用的方法/////////////
    public static ReportReqParam getChargeTimeReqParm(boolean isSuccess) {
        return getSetChargeTimeReqParm(isSuccess, "");
    }

    ///////////购买套餐包结果/////////////
    public static ReportReqParam getPayReqParam(String functionNameFindId, boolean isSuccess, String error) {
        return new ReportReqParam.ReportReqParamBuilder().channelId("0")
                .deviceType("0")
                .functionNameFindId(functionNameFindId)
                .objectID("")
                .objectType("9")
                .operationType("")
                .result(isSuccess ? "0" : "1")
                .error(error)
                .type("3")
                .createReportReqParam();
    }

    ////////////供调用的方法/////////////
    public static ReportReqParam getPayReqParam(String functionNameFindId, boolean isSuccess) {
        return getPayReqParam(functionNameFindId, isSuccess, "");
    }


    /**
     * 驾驶评分协议开闭状态report
     * @return
     */
    public static ReportReqParam getSmartDriveSettingReqParam(FunctionNameFindId functionNameFindId,boolean isSuccess,String error){
        return new ReportReqParam.ReportReqParamBuilder().channelId("0")
                .deviceType("0")
                .functionNameFindId(functionNameFindId.getStringValue())
                .objectID("")
                .objectType("9")
                .operationType("")
                .result(isSuccess ? "0" : "1")
                .error(error)
                .type("3")
                .createReportReqParam();
    }

    /**
     * 驾驶评分协议开闭状态report
     * @return
     */
    public static ReportReqParam getSmartDriveSettingReqParam(FunctionNameFindId functionNameFindId,boolean isSuccess){
        return getSmartDriveSettingReqParam(functionNameFindId,isSuccess,"");
    }

    /**
     * 爱车管理车况下拉刷新状态report
     * @return
     */
    public static ReportReqParam getVehcileDataRefreshReqParam(FunctionNameFindId functionNameFindId,boolean isSuccess, String error) {
        return new ReportReqParam.ReportReqParamBuilder().channelId("0")
                .deviceType("0")
                .functionNameFindId(functionNameFindId.getStringValue())
                .objectID("")
                .objectType("9")
                .operationType("")
                .result(isSuccess ? "0" : "1")
                .error(error)
                .type("3").createReportReqParam();
    }

    public static ReportReqParam getVehcileDataRefreshReqParam(FunctionNameFindId functionNameFindId,boolean isSuccess) {
        return getVehcileDataRefreshReqParam(functionNameFindId,isSuccess, "");
    }

    /**
     * 我的下拉刷新状态report
     * @return
     */
    public static ReportReqParam getMineRefreshReqParam(boolean isSuccess, String error) {
        return new ReportReqParam.ReportReqParamBuilder().channelId("0")
                .deviceType("0")
                .functionNameFindId(FunctionNameFindId.My_DragDownRefresh.getStringValue())
                .objectID("")
                .objectType("9")
                .operationType("")
                .result(isSuccess ? "0" : "1")
                .error(error)
                .type("3").createReportReqParam();
    }

    /**
     * 根据URL report
     * @return
     */
    public static ReportReqParam getURLReqParam() {
        return new ReportReqParam.ReportReqParamBuilder().channelId("0")
                .deviceType("0")
//                .objectID("")
                .objectType("3")
                .operationType("")
//                .error("")
                .type("3").createReportReqParam();
    }

    public static ReportReqParam getMineRefreshReqParam(boolean isSuccess) {
        return getMineRefreshReqParam(isSuccess, "");
    }

    //////////////////得到各种请求参数结束/////////////////////////////
}
